package com.TradeQuery;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter.ViewBinder;
import android.widget.TextView;



public class myAdapter extends BaseAdapter {	
	
	private LayoutInflater mInflater; 
	private List<Map<String, Object>> mData; 

	   
	   
	  public myAdapter( Context context, List<Map<String, Object>> m){
		  
		
		  this.mInflater = LayoutInflater.from(context); 	   
		  this.mData = m ;
	  }


	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size(); 
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null; 
		   if (convertView == null) { 
		    
		    holder=new ViewHolder();   
		    
		    convertView = mInflater.inflate(R.layout.tradelistview, null); 
		    holder.ItemImage = (ImageView)convertView.findViewById(R.id.ItemImage); 
		    holder.ItemTitle = (TextView)convertView.findViewById(R.id.ItemTitle); 
		    holder.ItemText = (TextView)convertView.findViewById(R.id.ItemText); 
		    holder.ItemTime = (TextView)convertView.findViewById(R.id.ItemTime); 
		    holder.ItemTID = (TextView)convertView.findViewById(R.id.ItemTID);
		    convertView.setTag(holder); 
		    
		   }else { 
		    
		    holder = (ViewHolder)convertView.getTag(); 
		   } 
		    
		    
		   holder.ItemImage.setBackgroundResource((Integer)mData.get(position).get("ItemImage")); 
		   holder.ItemTitle.setText((String)mData.get(position).get("ItemTitle")); 
		   holder.ItemText.setText((String)mData.get(position).get("ItemText"));
		   holder.ItemTime.setText((String)mData.get(position).get("ItemTime"));
		   holder.ItemTID.setText((String)mData.get(position).get("ItemTID"));
	
		   holder.ItemImage.setTag((String)mData.get(position).get("ItemTID"));
		   holder.ItemImage.setOnClickListener(new View.OnClickListener() {		    
		    
		    public void onClick(View v) { 
		    	//TextView tv = (TextView) v.getp.findViewById(R.id.ItemTID);		    	

	        		String sTID = (String)v.getTag();
	        		
	        		if( null != RunnigParms.getInstance().mainActivity
	        				&& null!=sTID && sTID.length() > 0)
	        		{
	        		
	        		RunnigParms.getInstance().mainActivity.showLongClickInfo(sTID);
	        		}
	        		
	            	   
		    } 
		   });    
		   return convertView; 

		
	}
	
	 
   
	
    public final class ViewHolder{ 
    	  public ImageView ItemImage; 
    	  public TextView ItemTitle; 
    	  public TextView ItemText; 
    	  public TextView ItemTime; 
    	  public TextView ItemTID;    	  
    	     
    	  //public Button viewBtn; 
    	} 
}
